Option Strict On

Public MustInherit Class Building
  ' To jest klasa bazowa, z ktrej wyprowadzamy 
  ' klasy Apartment, Commercial, Home.

  ' =============== Stae symboliczne ================

  Private Const APARTMENT As Integer = 0
  Private Const COMMERCIAL As Integer = 1
  Private Const HOME As Integer = 2
  ' Domylne numery telefonw do usuwania niegu
  Public Const APTPHONE As String = "555-1000"
  Public Const COMPHONE As String = "555-2000"
  Public Const HOMPHONE As String = "555-3000"

  ' ================== Skadniki danych ==================

  Private mAddress As String        ' Adres
  Private mPrice As Double          ' Cena nabycia
  Private mMonthlyPayment As Double ' Opaty miesiczne 
  Private mTaxes As Double          ' Podatki roczne
  Private mType As Integer          ' Typ budynku
  Private mSnowPhone As String      ' Kogo wezwa do odnieania

  ' ================== Konstruktor ==================

  Public Sub New()
    Address = "Pusty budynek"
  End Sub


  ' ==================== Waciwoci ======================

  Public Property Address() As String      ' Waciwo Adres
    Get
      Return mAddress
    End Get

    Set(ByVal Value As String)
      mAddress = Value
    End Set
  End Property

  Public Property PurchasePrice() As Double  ' Waciwo Cena nabycia
    Get
      Return mPrice
    End Get

    Set(ByVal Value As Double)
      mPrice = Value
    End Set
  End Property

  Public Property MonthlyPayment() As Double  ' Waciwo Opaty miesiczne
    Get
      Return mMonthlyPayment
    End Get

    Set(ByVal Value As Double)
      mMonthlyPayment = Value
    End Set
  End Property

  Public Property Taxes() As Double   ' Waciwo Podatek od nieruchomoci
    Get
      Return mTaxes
    End Get

    Set(ByVal Value As Double)
      mTaxes = Value
    End Set
  End Property

  Public Property BuildingType() As Integer   ' Wasciwo Typ budynku 
    Get
      Return mType
    End Get

    Set(ByVal Value As Integer)
      If Value < APARTMENT Or Value > HOME Then
        mType = -1  ' bd
      Else
        mType = Value
      End If
    End Set
  End Property

  Public Property SnowRemoval() As String    ' Wywoanie odnieania
    Get
      Return mSnowPhone
    End Get

    Set(ByVal Value As String)
      mSnowPhone = Value
    End Set
  End Property

  ' ========================== Metody ========================

  ' Zmuszamy klasy pochodne, aby podaway, do kogo dzwoni.
  Public MustOverride Function CallSnowRemoval() As String

  Protected Sub DisplayBaseInfo()
    Dim BldType As String

    ' Cel: wywietli podstawowe dane skadowe 
    Select Case mType       ' Jaki typ budynku?
      Case APARTMENT
        BldType = "Apartment"
      Case COMMERCIAL
        BldType = "Commercial"
      Case HOME
        BldType = "Home"
    End Select
    Console.WriteLine()
    Console.WriteLine("---------- " & BldType & " -----------")
    Console.WriteLine("Address: " & mAddress)
    Console.WriteLine("Purchase Price: " & FormatMoney(mPrice))
    Console.WriteLine("Monthly Payment: " & _
                       FormatMoney(mMonthlyPayment))
    Console.WriteLine("Property Taxes: " & FormatMoney(mTaxes))
    Console.WriteLine("Building Type: " & BldType)
    Console.WriteLine("Snow removal Phone: " & mSnowPhone)
    Console.WriteLine()
  End Sub

  ' =========================== Programy pomocnicze ========================

  Protected Function FormatMoney(ByVal num As Double) As String
    ' Cel: formatowanie wartoci dolara
    '
    ' Argumenty:
    '  num   Liczba typu double, ktra jest wartoci dolara do 
    '        sformatowania
    '
    ' Zwracana warto:
    '  string   acuch wartoci w formacie dolara

    Return Format(num, "$#,###,###,###.00")
  End Function

End Class

' ++++++++++++++++++++++++++++ Klasa Apartment ++++++++++++++++++++++++

Public Class Apartment
  Inherits Building

  Private mUnits As Integer    ' Liczba mieszka
  Private mRent As Double      ' Cena najmu na jednostk
  Private mOccupRate As Double ' Wspczynnik zajcia budynku 

  Public Sub New()

  End Sub

  ' Konstruktor z inicjalizujac list argumentw
  Public Sub New(ByVal Addr As String, ByVal Price As Double, _
            ByVal Payment As Double, ByVal Taxes As Double, _
            ByVal Bldg As Integer, ByVal SnowPhone As String)
    MyBase.Address = Addr
    MyBase.PurchasePrice = Price
    MyBase.MonthlyPayment = Payment
    MyBase.Taxes = Taxes
    MyBase.BuildingType = Bldg
    If SnowPhone = "" Then
      MyBase.SnowRemoval = APTPHONE
    Else
      MyBase.SnowRemoval = SnowPhone
    End If
  End Sub
  ' ==================== Waciwoci ======================

  Public Property Units() As Integer    ' Mieszkania
    Get
      Return mUnits
    End Get
    Set(ByVal Value As Integer)
      mUnits = Value
    End Set
  End Property

  Public Property Rents() As Double     ' Koszty najmu
    Get
      Return mRent
    End Get
    Set(ByVal Value As Double)
      mRent = Value
    End Set
  End Property

  Public Property OccupancyRate() As Double ' Wspczynnik zajcia
    Get
      Return mOccupRate
    End Get
    Set(ByVal Value As Double)
      mOccupRate = Value
    End Set
  End Property

  ' ============== Metody ==================

  Public Overrides Function CallSnowRemoval() As String
    ' Cel: ta procedura jest wywoywana, aby usun nieg przed blokiem.
    '    
    Return "Usuwanie niegu przed blokiem: " & MyBase.SnowRemoval
  End Function

  Public Sub DisplayBuilding()

    DisplayBaseInfo()
    Console.WriteLine("Apartment members:")
    Console.WriteLine("Number of Units: " & mUnits)
    Console.WriteLine("Rent per Unit: " & FormatMoney(mRent))
    Console.WriteLine("Occupancy Rate: " & mOccupRate)
  End Sub
End Class

' ++++++++++++++++++++++++++++ Klasa Commercial ++++++++++++++++++++++++++

Public Class Commercial
  Inherits Building

  Private mSquareFeet As Integer  ' Powierzchnia do wynajcia
  Private mRentPerSF As Double    ' Cena najmu
  Private mParking As Integer     ' Miejsca parkingowe

  Public Sub New()  ' Konstruktor bez argumentw

  End Sub

  Public Sub New(ByVal Addr As String, ByVal Price As Double, _
           ByVal Payment As Double, ByVal Taxes As Double, _
           ByVal Bldg As Integer, ByVal SnowPhone As String)
    MyBase.Address = Addr
    MyBase.PurchasePrice = Price
    MyBase.MonthlyPayment = Payment
    MyBase.Taxes = Taxes
    MyBase.BuildingType = Bldg
    If SnowPhone = "" Then
      MyBase.SnowRemoval = COMPHONE
    Else
      MyBase.SnowRemoval = SnowPhone
    End If
  End Sub

  ' ==================== Waciwoci ======================

  Public Property SquareFeet() As Integer   ' Powierzchnia
    Get
      Return mSquareFeet
    End Get
    Set(ByVal Value As Integer)
      mSquareFeet = Value
    End Set
  End Property

  Public Property RentPerSF() As Double    ' Cena wynajmu
    Get
      Return mRentPerSF
    End Get
    Set(ByVal Value As Double)
      mRentPerSF = Value
    End Set
  End Property

  Public Property ParkingSpots() As Integer  ' Miejsca parkingowe
    Get
      Return mParking
    End Get
    Set(ByVal Value As Integer)
      mParking = Value
    End Set
  End Property

  ' ============== Metody ==================

  Public Overrides Function CallSnowRemoval() As String
    ' Cel: ta procedura jest wywoywana, aby usun nieg przed budynkiem 
    '      komercyjnym.
    '      
    Return "Commercial snow removal: " & _
            MyBase.SnowRemoval
  End Function

  Public Sub DisplayBuilding()
    DisplayBaseInfo()        ' Wywoanie klasy bazowej
    Console.WriteLine("      Commercial members:")
    Console.WriteLine("Square Feet: " & mSquareFeet)
    Console.WriteLine("Rent per SF: " & FormatMoney(mRentPerSF))
    Console.WriteLine("Parking Spots: " & mParking)
  End Sub
End Class

' ++++++++++++++++++++++++++++ Klasa Home ++++++++++++++++++++++++++++

Public NotInheritable Class Home
  Inherits Building

  Private mSquareFeet As Integer    ' Powierzchnia domu
  Private mRentPerMonth As Double   ' Cena najmu na miesic
  Private mBedrooms As Integer      ' Liczba sypialni
  Private mBaths As Integer         ' Liczba azienek

  ' ==================== Waciwoci ======================

  Public Sub New()  ' Konstruktor bez argumentw

  End Sub

  Public Sub New(ByVal Addr As String, ByVal Price As Double, _
           ByVal Payment As Double, ByVal Taxes As Double, _
           ByVal Bldg As Integer, ByVal SnowPhone As String)
    MyBase.Address = Addr
    MyBase.PurchasePrice = Price
    MyBase.MonthlyPayment = Payment
    MyBase.Taxes = Taxes
    MyBase.BuildingType = Bldg
    If SnowPhone = "" Then
      MyBase.SnowRemoval = HOMPHONE
    Else
      MyBase.SnowRemoval = SnowPhone
    End If

  End Sub

  Public Property SquareFeet() As Integer    ' Powierzchnia w m2
    Get
      Return mSquareFeet
    End Get
    Set(ByVal Value As Integer)
      mSquareFeet = Value
    End Set
  End Property

  Public Property Rent() As Double       ' Cena najmu
    Get
      Return mRentPerMonth
    End Get
    Set(ByVal Value As Double)
      mRentPerMonth = Value
    End Set
  End Property

  Public Property Bedrooms() As Integer     ' Sypialnie
    Get
      Return mBedrooms
    End Get
    Set(ByVal Value As Integer)
      mBedrooms = Value
    End Set
  End Property

  Public Property Baths() As Integer       ' azienki
    Get
      Return mBaths
    End Get
    Set(ByVal Value As Integer)
      mBaths = Value
    End Set
  End Property

  ' ============== Metody ==================

  Public Overrides Function CallSnowRemoval() As String
    ' Cel: ta procedura wywouje usuwanie niegu przed domem.
    '      
    Return "Home snow removal: " & MyBase.SnowRemoval
  End Function

  Public Sub DisplayBuilding()

    MyBase.DisplayBaseInfo()        ' Wywoanie klasy bazowej
    Console.WriteLine("      Home members:")
    Console.WriteLine("Square Feet: " & mSquareFeet)
    Console.WriteLine("Rent per Month: " & _
            FormatMoney(mRentPerMonth))
    Console.WriteLine("Bedrooms: " & mBedrooms)
    Console.WriteLine("Baths: " & mBaths)
  End Sub
End Class
